package controllers

import (
	"gitee.com/tsingeye/FreeEhome/models"
	"strings"
)

/**
 * @apiDefine stream 实时直播接口
 */
type StreamController struct {
	AuthController
}

/**
 * @api {get} /api/v1/channels/:channelID/inviteStream 指定通道实时直播启动
 * @apiVersion 1.0.0
 * @apiGroup stream
 * @apiName InviteStream
 * @apiParam {String} [channelType] 码流类型 主码流：MAIN；子码流：SUB；三码流：THIRD。默认使用子码流
 * @apiSuccessExample  {json} Response-Example
 * {
 *   "errCode": 200,
 *   "errMsg": "Success OK",
 *   "urlMap": {
 *     "rtmp": "rtmp://127.0.0.1:1935/live/xxx",
 *     "flv": "http://127.0.0.1:80/live/xxx.flv",
 *     "rtsp": "rtsp://127.0.0.1:554/live/xxx",
 *     "hls": "http://127.0.0.1:80/live/xxx/hls.m3u8"
 *    }
 * }
 */
func (this *StreamController) InviteStream() {
	channelID := this.Ctx.Input.Param(":channelID")
	channelType := strings.ToUpper(this.GetString("channelType"))

	this.Data["json"] = models.InviteStream(channelID, channelType)
	this.ServeJSON()
}

/**
 * @api {get} /api/v1/channels/:channelID/getSnap 获取快照
 * @apiVersion 1.0.0
 * @apiGroup stream
 * @apiName GetSnap
 * @apiSuccessExample  {json} Response-Example
 * {
 *   "errCode": 200,
 *   "errMsg": "Success OK",
 *   "snapsData": "图片信息" //base64加密的图片信息
 * }
 */
func (this *StreamController) GetSnap() {
	channelID := this.Ctx.Input.Param(":channelID")

	this.Data["json"] = models.GetSnap(channelID, false)
	this.ServeJSON()
}
